import { describe, expect, test } from 'vitest';
import {
  camelToUnderline,
  underlineToCamel,
} from '../../src/hammer/nameFormatter.mts';

describe('字符串格式转换工具函数', () => {
  describe('camelToUnderline', () => {
    test('基本驼峰转下划线转换', () => {
      expect(camelToUnderline('helloWorld')).toBe('hello_world');
      expect(camelToUnderline('userName')).toBe('user_name');
      expect(camelToUnderline('CamelCaseExample')).toBe('_camel_case_example');
    });

    test('包含数字的驼峰转下划线', () => {
      expect(camelToUnderline('item2')).toBe('item2');
      expect(camelToUnderline('user2Name')).toBe('user2_name');
      expect(camelToUnderline('version1_0')).toBe('version1_0');
    });

    test('包含特殊字符的驼峰转下划线', () => {
      expect(camelToUnderline('hello_world')).toBe('hello_world');
      expect(camelToUnderline('hello-world')).toBe('hello-world');
      expect(camelToUnderline('hello@World')).toBe('hello@_world');
    });

    test('边界情况处理', () => {
      expect(camelToUnderline('')).toBe('');
      expect(camelToUnderline('a')).toBe('a');
      expect(camelToUnderline('A')).toBe('_a');
      expect(camelToUnderline('ABC')).toBe('_a_b_c');
    });
  });

  describe('underlineToCamel', () => {
    test('基本下划线转驼峰转换', () => {
      expect(underlineToCamel('hello_world')).toBe('helloWorld');
      expect(underlineToCamel('user_name')).toBe('userName');
      expect(underlineToCamel('_camel_case_example')).toBe('camelCaseExample');
    });

    test('包含数字的下划线转驼峰', () => {
      expect(underlineToCamel('item2')).toBe('item2');
      expect(underlineToCamel('user2_name')).toBe('user2Name');
      expect(underlineToCamel('version1_0')).toBe('version10');
    });

    test('包含特殊字符的下划线转驼峰', () => {
      expect(underlineToCamel('hello-world')).toBe('hello-world');
      expect(underlineToCamel('hello@_world')).toBe('hello@World');
      expect(underlineToCamel('hello__world')).toBe('helloWorld');
    });

    test('边界情况处理', () => {
      expect(underlineToCamel('')).toBe('');
      expect(underlineToCamel('a')).toBe('a');
      expect(underlineToCamel('_a')).toBe('a');
      expect(underlineToCamel('a_b_c')).toBe('aBC');
    });
  });
});
